package com.innovation.chengzhangriji.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.innovation.chengzhangriji.Config;
import com.innovation.chengzhangriji.R;
import com.innovation.chengzhangriji.ui.widget.SelectLayout;

/**
 * 新日记
 */
public class Select1Fragment extends Fragment implements SelectLayout.OnClickSelectListener {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_create1, container, false);
        SelectLayout item1 = (SelectLayout) view.findViewById(R.id.select_item_1);
        SelectLayout item2 = (SelectLayout) view.findViewById(R.id.select_item_2);
        SelectLayout item3 = (SelectLayout) view.findViewById(R.id.select_item_3);
        item1.setOnClickSelectListener(this);
        item2.setOnClickSelectListener(this);
        item3.setOnClickSelectListener(this);
        return view;
    }

    @Override
    public void onClickSelect(View view) {
        int state = Config.EXTRA_OPEN_CREATE_STATE_READY;
        switch (view.getId()) {
            case R.id.select_item_1:
                state = Config.EXTRA_OPEN_CREATE_STATE_READY;
                break;
            case R.id.select_item_2:
                state = Config.EXTRA_OPEN_CREATE_STATE_START;
                break;
            case R.id.select_item_3:
                state = Config.EXTRA_OPEN_CREATE_STATE_END;
                break;
        }
        startCreateActivity(state);
    }

    private void startCreateActivity(int state) {
        Intent intent = new Intent(getActivity(), CreateActivity.class);
        intent.putExtra(Config.ACTION_EXTERNAL_OPEN_CREATE_STATE, state);
        startActivity(intent);
        getActivity().finish();
    }
}
